from node import Node
from board import Board
from node import *
import sys
import pygame
from pygame.locals import *

'''
' Loads the word dictionary into a tree
'''
def load_dictionary(path):
    tree = Node()
    for line in open(path, 'r'):
        word = line.strip().lower()
        tree.add(word)
    return tree

def main():
    print 'Loading word list.'
    
    words = load_dictionary('words.txt')
    board = Board()
    
    pygame.init()
    size = width, height = 300, 300

    screen = pygame.display.set_mode(size)

    clock = pygame.time.Clock()
    
    #Game loop
    while True:
        clock.tick(60)
        
        #event checking
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return
        #test code, drawing on screen
        screen.fill(pygame.Color(255, 255, 255))
        pygame.draw.rect(screen, pygame.Color(0, 0, 0), (0, 0, 100, 100))
        pygame.display.flip()
        #test code end
        
        #just for testing anagrams for now
        #letters = raw_input('Enter letters: ')
        #letters = letters.lower()
        #letters = letters.replace(' ', '')
        letters = board.get_all_letters()
        
        if not letters:
            break
        count = 0
        for word in words.find_anagrams(letters):
            print word
            count += 1
        print '%d results.' % count

if __name__ == '__main__':
    print "Start"
    main()